home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Chat / server / FriendsServer$RecThread.class (.txt) < prev   
Encoding:
Java Class File  |  2001-10-30  |  5.2 KB  |  192 lines

  1. import java.io.BufferedInputStream;
  2. import java.io.DataInputStream;
  3. import java.io.DataOutputStream;
  4. import java.net.Socket;
  5.  
  6. class FriendsServer$RecThread extends Thread {
  7.    // $FF: synthetic field
  8.    private final FriendsServer this$FriendsServer;
  9.    Socket socket;
  10.    // $FF: renamed from: in java.io.DataInputStream
  11.    DataInputStream field_0;
  12.    DataOutputStream out;
  13.    String[] arg;
  14.    String nick;
  15.    FriendsServer parent;
  16.    boolean is_nick;
  17.  
  18.    FriendsServer$RecThread(FriendsServer var1, Socket var2, int var3, FriendsServer var4) {
  19.       this.this$FriendsServer = var1;
  20.       this.this$FriendsServer = var1;
  21.       this.nick = "";
  22.       this.socket = var2;
  23.       this.parent = var4;
  24.       this.arg = new String[4];
  25.  
  26.       for(int var5 = 0; var5 < 4; ++var5) {
  27.          this.arg[var5] = "";
  28.       }
  29.  
  30.    }
  31.  
  32.    public synchronized void send(String var1) {
  33.       if (this.this$FriendsServer.debug) {
  34.          System.out.println("sending: " + var1);
  35.       }
  36.  
  37.       if (var1 != null) {
  38.          try {
  39.             this.out.writeBytes(var1);
  40.          } catch (Exception var2) {
  41.             if (this.this$FriendsServer.debug) {
  42.                System.out.println("absence de la socket " + Integer.toString(this.this$FriendsServer.giveId(this.nick)));
  43.             }
  44.  
  45.             this.parent.stop(this.this$FriendsServer.giveId(this.nick), 1);
  46.          }
  47.       }
  48.    }
  49.  
  50.    public char readByte() {
  51.       char var1 = ' ';
  52.  
  53.       try {
  54.          byte var2 = this.field_0.readByte();
  55.          var1 = (char)(var2 < 0 ? 256 + var2 : var2);
  56.       } catch (Exception var3) {
  57.          if (this.this$FriendsServer.debug) {
  58.             System.out.println("fermeture de la socket " + Integer.toString(this.this$FriendsServer.giveId(this.nick)));
  59.          }
  60.  
  61.          this.parent.stop(this.this$FriendsServer.giveId(this.nick), 1);
  62.       }
  63.  
  64.       return var1;
  65.    }
  66.  
  67.    public void read() {
  68.       int var1 = 0;
  69.       int var2 = 0;
  70.       char[] var3 = new char[1024];
  71.       char var4 = this.readByte();
  72.       if (this.this$FriendsServer.debug) {
  73.          System.out.print("receiving: ");
  74.       }
  75.  
  76.       for(; var4 != '\n'; var4 = this.readByte()) {
  77.          if (var4 == ' ' && var1 < 3) {
  78.             this.arg[var1] = new String(var3, 0, var2);
  79.             ++var1;
  80.             var2 = 0;
  81.          } else if (var2 < 1024) {
  82.             var3[var2++] = var4;
  83.          } else {
  84.             this.parent.stop(this.this$FriendsServer.giveId(this.nick), 1);
  85.          }
  86.       }
  87.  
  88.       this.arg[var1] = new String(var3, 0, var2 >= 1024 ? 1024 : var2);
  89.       if (var1 != 3) {
  90.          this.arg[3] = "";
  91.       }
  92.  
  93.       if (this.this$FriendsServer.debug) {
  94.          for(int var5 = 0; var5 < 4; ++var5) {
  95.             System.out.print(this.arg[var5] + " ");
  96.          }
  97.  
  98.          System.out.println("fin receiving");
  99.       }
  100.  
  101.    }
  102.  
  103.    public void run() {
  104.       this.is_nick = false;
  105.       if (this.this$FriendsServer.debug) {
  106.          System.out.println("thread " + Integer.toString(this.this$FriendsServer.giveId(this.nick)) + " demarre");
  107.       }
  108.  
  109.       try {
  110.          this.field_0 = new DataInputStream(new BufferedInputStream(this.socket.getInputStream()));
  111.          this.out = new DataOutputStream(this.socket.getOutputStream());
  112.       } catch (Exception var4) {
  113.          System.out.println(var4);
  114.       }
  115.  
  116.       if (this.this$FriendsServer.debug) {
  117.          System.out.println("entrees sorties crees");
  118.       }
  119.  
  120.       while(true) {
  121.          this.read();
  122.          if (this.arg[0].equals("NICK")) {
  123.             if (!this.is_nick) {
  124.                if (this.parent.isNick(this.arg[1])) {
  125.                   this.send(this.nick + " 901\n");
  126.                } else {
  127.                   this.nick = this.arg[1];
  128.                   this.is_nick = true;
  129.                   this.send(this.nick + " 001\n");
  130.                   this.send(this.nick + " 002 dea " + this.parent.giveNicks() + "\n");
  131.                   this.parent.sendAll(this.this$FriendsServer.giveId(this.nick), this.nick + " JOIN\n");
  132.                   if (this.this$FriendsServer.topic != null) {
  133.                      this.send(this.nick + " 003 " + this.this$FriendsServer.topicAuthor + " " + this.this$FriendsServer.topic + "\n");
  134.                   }
  135.                }
  136.             } else if (this.parent.isNick(this.arg[1])) {
  137.                this.send(this.nick + " 901\n");
  138.             } else {
  139.                String var8 = this.nick;
  140.                this.nick = this.arg[1].trim();
  141.                this.parent.sendAll(var8 + " NICK " + this.nick + "\n");
  142.             }
  143.          } else if (this.arg[0].equals("QUIT")) {
  144.             try {
  145.                this.field_0.close();
  146.                this.out.close();
  147.                this.socket.close();
  148.                this.parent.stop(this.this$FriendsServer.giveId(this.nick), 0);
  149.             } catch (Exception var3) {
  150.                System.err.println(var3);
  151.             }
  152.          } else if (this.arg[1].equals("MSG")) {
  153.             this.this$FriendsServer.sendAll(this.this$FriendsServer.giveId(this.nick), this.arg[0] + " MSG @ " + this.arg[3] + "\n");
  154.          } else if (this.arg[1].equals("ME")) {
  155.             this.this$FriendsServer.sendAll(this.this$FriendsServer.giveId(this.nick), this.arg[0] + " ME @ " + this.arg[3] + "\n");
  156.          } else if (this.arg[1].equals("TOPIC")) {
  157.             this.this$FriendsServer.topic = this.arg[3];
  158.             this.this$FriendsServer.topicAuthor = this.arg[0];
  159.             this.this$FriendsServer.sendAll(this.arg[0] + " TOPIC @ " + this.arg[3] + "\n");
  160.          } else if (this.arg[1].equals("BEEP")) {
  161.             int var1 = this.this$FriendsServer.giveId(this.arg[2]);
  162.             if (var1 != -1) {
  163.                this.this$FriendsServer.sendOne(var1, this.arg[0] + " BEEP\n");
  164.             } else {
  165.                this.this$FriendsServer.sendOne(this.this$FriendsServer.giveId(this.arg[0]), this.arg[0] + " 902\n");
  166.             }
  167.          } else if (this.arg[1].equals("PRIV")) {
  168.             int var5 = this.this$FriendsServer.giveId(this.arg[2]);
  169.             if (var5 != -1) {
  170.                this.this$FriendsServer.sendOne(var5, this.arg[0] + " PRIV @ " + this.arg[3] + "\n");
  171.             } else {
  172.                this.this$FriendsServer.sendOne(this.this$FriendsServer.giveId(this.arg[0]), this.arg[0] + " 902\n");
  173.             }
  174.          } else if (this.arg[1].startsWith("92")) {
  175.             int var6 = this.this$FriendsServer.giveId(this.arg[2]);
  176.             if (var6 != -1) {
  177.                this.this$FriendsServer.sendOne(var6, this.arg[0] + " " + this.arg[1] + "\n");
  178.             }
  179.          } else if (this.arg[1].equals("WHOIS")) {
  180.             int var7 = this.this$FriendsServer.giveId(this.arg[2]);
  181.             if (var7 == -1) {
  182.                this.this$FriendsServer.sendOne(this.this$FriendsServer.giveId(this.arg[0]), this.arg[0] + " 902\n");
  183.             } else {
  184.                String var2 = this.arg[2] + " whois infos: " + ((FriendsServer$RecThread)this.this$FriendsServer.thread.elementAt(var7)).socket.getInetAddress().getHostName();
  185.                var2 = var2 + " - " + ((FriendsServer$RecThread)this.this$FriendsServer.thread.elementAt(var7)).socket.getInetAddress().getHostAddress();
  186.                this.this$FriendsServer.sendOne(this.this$FriendsServer.giveId(this.arg[0]), this.arg[0] + " WHOIS @ " + var2 + "\n");
  187.             }
  188.          }
  189.       }
  190.    }
  191. }
  192.